package dao

import (
	"ssims/models"
)

func GetAllEvent(event map[string]interface{}) (error, []models.Event, int64) {
	var eventData []models.Event
	page := event["page"].(int)
	pageSize := event["limit"].(int)
	searchId := event["searchId"].(string)
	var total int64
	err := db.Table("event").Select("family_id", "event_time", "event_type", "event_des", "event_fj").Where("family_id like ? and is_del = false", searchId+"%").Order("family_id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&eventData).Error
	return err, eventData, total
}
func GetAllEvent1(event map[string]interface{}) (error, []models.Event, int64) {
	var eventData []models.Event
	page := event["page"].(int)
	pageSize := event["limit"].(int)
	searchId := event["searchId"].(string)
	var total int64
	err := db.Table("event").Select("family_id", "event_time", "event_type", "event_des", "event_fj").Where("family_id like ? and is_del = false", searchId+"%").Order("family_id ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&eventData).Error
	return err, eventData, total
}

func DelEvent(id string) error {
	err := db.Table("event").Where("family_id = ?", id).Update("is_del", true).Error
	return err
}

func UpdateEvent(event models.Event) error {
	err := db.Table("event").Select("family_id", "event_time", "event_type", "event_des", "event_fj").Where("family_id = ?", event.FamilyId).Updates(&event).Error
	return err
}

func AddEvent(event models.Event) error {
	err := db.Table("event").Select("family_id", "event_time", "event_type", "event_des", "event_fj", "is_del").Create(&event).Error
	return err
}
